﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using WaterRevenueMS.Core.Repository.BasicSet;
using WaterRevenueMS.Componnent.Entities.BasicSet;
using WaterRevenueMS.Componnent.Common;
using WaterRevenueMS.Domain.ViewModels.BasicSet.SysParam;

namespace WaterRevenueMS.Core.Service.BasicSet.Impl
{
    [Export(typeof(ISysParamService))]
    public class SysParamService : CoreServiceBase, ISysParamService
    {
        [Import]
        public ISysParamRepository SysParamRepository { get; set; }

        public IQueryable<SysParam> SysParams
        {
            get { return SysParamRepository.Entities; }
        }

        public OperationResult Insert(SysParamModel model)
        {
            var entity = new SysParam
            {
                CreateDT=DateTime.Now,
                ReviseDT=DateTime.Now,
                OrderNo=model.OrderNo,
                Shi_SXS=model.Shi_SXS,
                Yong_LQZ=model.Yong_LQZ,
                Yong_LXS=model.Yong_LXS,
                Dan_JXS=model.Dan_JXS,
                Fei_YQZ=model.Fei_YQZ,
                Fei_YXS=model.Fei_YXS,
                Fu_YLBJ=model.Fu_YLBJ,
                Fu_YLGZ=model.Fu_YLGZ,
                Huan_BZQ=model.Huan_BZQ,
                Huan_BTX=model.Huan_BTX,
                Qian_FHB=model.Qian_FHB,
                Qian_FBG=model.Qian_FBG

            };
            SysParamRepository.Insert(entity);
            return new OperationResult(OperationResultType.Success, "添加成功");
        }

        public OperationResult Update(SysParamModel model)
        {
            var entity = SysParamRepository.Entities.FirstOrDefault(t => t.Id == model.Id);
            if (entity != null)
            {
                entity.ReviseDT = DateTime.Now;
                entity.OrderNo = model.OrderNo;
                entity.Shi_SXS = model.Shi_SXS;
                entity.Yong_LQZ = model.Yong_LQZ;
                entity.Yong_LXS = model.Yong_LXS;
                entity.Dan_JXS = model.Dan_JXS;
                entity.Fei_YQZ = model.Fei_YQZ;
                entity.Fei_YXS = model.Fei_YXS;
                entity.Fu_YLBJ = model.Fu_YLBJ;
                entity.Fu_YLGZ = model.Fu_YLGZ;
                entity.Huan_BZQ = model.Huan_BZQ;
                entity.Huan_BTX = model.Huan_BTX;
                entity.Qian_FHB = model.Qian_FHB;
                entity.Qian_FBG = model.Qian_FBG;
                SysParamRepository.Update(entity);
            }
            return new OperationResult(OperationResultType.Success, "更新成功");
        }

        public OperationResult Delete(int Id)
        {
            var entity = SysParamRepository.Entities.FirstOrDefault(t => t.Id == Id);
            if (entity != null)
            {
                SysParamRepository.Delete(entity);
            }
            return new OperationResult(OperationResultType.Success, "删除成功");
        }
    }
}
